unit con_Descontouf;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,db, dbtables;

type
  TFrmCon_DescontoUf = class(TFrmConsulta)
    Label1: TLabel;
    cb_Estado: TComboBox;
    dbg: TDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure cb_EstadoExit(Sender: TObject);
    procedure BtnFecharClick(Sender: TObject);
  private
    procedure FazConsulta;
    { Private declarations }
  public
    xcodigo_dscuf : string; 
    { Public declarations }
  end;

var
  FrmCon_DescontoUf: TFrmCon_DescontoUf;

implementation

uses Biblio, Dm, clsDescontoUF;

var descuf : TDescontoUF;
    tds    : Tdatasource;
    tq     : Tquery;

{$R *.DFM}

procedure TFrmCon_DescontoUf.FormCreate(Sender: TObject);
begin
  inherited;
  descuf := TDescontoUF.create;
end;

procedure TFrmCon_DescontoUf.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  descuf.free;
end;

procedure TFrmCon_DescontoUf.FormActivate(Sender: TObject);
begin
  inherited;
  tds             := TDataSource.create(FrmCon_DescontoUf);
  tq              := Tquery.create(FrmCon_DescontoUf);
  tq.databasename := dmint.db.databasename;
  tq.active       := False;
  tds.DataSet     := tq;
  dbg.DataSource  := tds;
  FazConsulta;
  cb_Estado.setfocus;
end;

procedure TFrmCon_DescontoUf.FazConsulta;
var xest : string;
begin
  xest := copy(cb_Estado.Text,1,2);
  If trim(xest) = '' then
    descuf.Consultartodos(tq)
  else
    descuf.Consultar(tq,xest);
  tq.open;
  dbg.DataSource := tds;
  dbg.Refresh;
end;

procedure TFrmCon_DescontoUf.cb_EstadoExit(Sender: TObject);
begin
  inherited;
  FazConsulta;
end;

procedure TFrmCon_DescontoUf.BtnFecharClick(Sender: TObject);
begin
  inherited;
  xcodigo_dscuf := tq.fieldbyname('desc_Codigo').asstring;
  tds.free;
  tq.free;
end;

end.
